/**
 * @file client_controller.h
 * @author 王烨
 * @date 2011-01-09
**/
#ifndef CLIENT_CONTROLLER_H_INCLUDED
#define CLIENT_CONTROLLER_H_INCLUDED

#include <string>
#include <cassert>

#include <google/protobuf/service.h>
#include <google/protobuf/stubs/common.h>

#include "sync_channel.h"
#include "async_channel.h"

namespace skeleton
{
  class ClientController : public google::protobuf::RpcController
  {
    friend class SyncChannel;
    friend class AsyncChannel;
  public:
    ClientController();
    virtual ~ClientController(){}
    virtual void Reset();
    virtual void StartCancel(){assert(false);}
    virtual bool Failed() const {return hasError;}
    virtual std::string ErrorText() const;
    ErrorCode GetErrorCode() const;

    /*以下函数不会在客户端使用*/
    virtual void SetFailed(const std::string &detial) {assert(false);}
    virtual bool IsCanceled() const {assert(false);}
    virtual void NotifyOnCancel(google::protobuf::Closure *callback) {assert(false);}
  private:
    bool hasError;
    ErrorCode errorCode;
    std::string errorText;
    void SetError(ErrorCode errorCode, const std::string &errorText);
  };
}
#endif
